package com.lineage.server.command.executor;

import com.lineage.config.Config;
import com.lineage.server.datatables.lock.AuctionBoardReading;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.templates.L1AuctionBoardTmp;
import com.lineage.server.world.World;
import java.util.Calendar;
import java.util.Iterator;
import java.util.TimeZone;

public class L1ReBoard implements L1CommandExecutor {
  public static L1CommandExecutor getInstance() {
    return new L1ReBoard();
  }
  
  public void execute(L1PcInstance pc, String cmdName, String arg) {
    try {
      Calendar DeadTime = getRealTime();
      DeadTime.add(12, Integer.parseInt(arg));
      Iterator<L1AuctionBoardTmp> localIterator = AuctionBoardReading.get().getAuctionBoardTableList()
        .values().iterator();
      while (localIterator.hasNext()) {
        L1AuctionBoardTmp board = localIterator.next();
        board.setDeadline(DeadTime);
        AuctionBoardReading.get().updateAuctionBoard(board);
      } 
      World.get().broadcastPacketToAll((ServerBasePacket)new S_SystemMessage("血盟小屋将在" + arg + "分钟后结标，需要购买的请尽快下标。"));
    } catch (Exception e) {
      pc.sendPackets((ServerBasePacket)new S_SystemMessage("请输入 " + cmdName + " 分钟数"));
    } 
  }
  
  private Calendar getRealTime() {
    TimeZone tz = TimeZone.getTimeZone(Config.TIME_ZONE);
    Calendar cal = Calendar.getInstance(tz);
    return cal;
  }
}
